Skip to content

fix(id/web): per-block indent/dedent for multi-block selections (#1399) - #2872

Merged
dezren39 merged 3 commits into
mainfrom
queue/1682-1399-multiblock-indent
Oct 31, 2026
Merged

dezren39 merged 3 commits into
mainfrom
queue/1682-1399-multiblock-indent

Conversation

@dezren39

@dezren39 dezren39 commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Fixes #1399 (queue task 1682).

Problem

indentCommand/dedentCommand in pkgs/id/web/src/indent.ts derived blockStart from $from and blockEnd from $to — different nodes when a selection spans blocks — and scanned doc.textBetween across block boundaries as one block's text. With a selection spanning code_block(x\ny) + paragraph(mid) + code_block(p\nq), Tab indented block 1, appended spaces to the prose (mid ), and skipped block 2.

Fix

Both commands now iterate every code_block intersecting the selection (doc.nodesBetween) and do line math per block: each block's own start/end, line starts from its own text, selection portion clamped to the block, reusing selectedLineStarts per block (including the #1038 binary-search helper, unchanged). Dedent removes up to 2 leading spaces per overlapped line using that block's own text. Edits are collected against the original doc and applied in descending position order. Non-code content is never modified; a selection overlapping no code block still returns false.

Single-block and single-cursor semantics are unchanged (verified by the existing 22 tests passing unmodified, including the #714 cases).

Tests

  • cd pkgs/id/web && bunx vitest run src/indent.test.ts — 28/28 pass (22 existing + 6 new #1399 tests: code+paragraph+code and code+paragraph selections for both commands, plus no-overlap-returns-false for both).
  • tsc --noEmit — clean.
  • Full package suite: 482 passed, 9 skipped, 1 failed in search-panel.test.ts (aria-label Replace all matches vs Replace all) — pre-existing on clean main, unrelated to this change (verified with this branch's changes stashed).

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

Tab/Shift-Tab with a selection spanning multiple blocks corrupted a
neighbouring paragraph and skipped later code blocks: line math ran on
doc.textBetween across block boundaries as one block's text. Iterate
every code_block intersecting the selection and do line math per block,
clamped to the selection portion; non-code content is never modified.

Adds code+paragraph(+code) regression tests for both commands.
@dezren39
dezren39 requested a review from a team as a code owner October 30, 2026 23:45
@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 31 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1a98c10e-bc1b-420e-8ec5-054b5253e87e
Commits

Reviewing files that changed from the base of the PR and between c6564aa and 8bfaaf5.

Files selected for processing: 2
  • pkgs/id/web/src/indent.test.ts
  • pkgs/id/web/src/indent.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-31T02:47:28.250767Z 8bfaaf5 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f3e29857b6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pkgs/id/web/src/indent.ts Outdated
// Strict overlap: a selection merely touching the block's edge
// covers none of its characters, so the block is skipped.
if (contentStart >= to || contentEnd <= from) continue;
for (const lineStart of selectedLineStarts(lineStarts, Math.max(from, contentStart), Math.min(to, contentEnd))) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve selected trailing empty lines when clamping ranges

When a selection continues beyond a code block ending in \n, clamping its endpoint to contentEnd makes selectedLineStarts exclude the block's trailing empty line: that position is also a line start, which the helper treats as an exclusive selection boundary. For example, selecting across code_block("a\n") + code_block("b") now leaves the first block as " a\n" instead of " a\n ", regressing indentation of that selected blank line. Preserve the distinction between a selection actually ending at that line start and one continuing into another block.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disposition (queue worker, lane D, task 1682): CONFIRMED valid — will fix, not merge past it. Root cause as described: indentCommand/dedentCommand clamp the per-block end to contentEnd (indent.ts:138), so selectedLineStarts sees an endpoint exactly on the trailing line start and applies its exclusive-boundary rule (#714), even though the real selection continues into the next block. Fix direction: distinguish a clamped end from a true selection end (e.g. pass a flag / use contentEnd+epsilon when the unclamped selection extends beyond this block) so the trailing empty line is included only when the selection actually continues past it; add a regression test for code_block("a\n") + code_block("b") cross-block selection. Blocked this shift on the laptop SSH outage (fleet rule: edits in a laptop worktree); task 1682 parked on that + this fix.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9d5d262 (queue worker lane E, task 1682): selectedLineStarts gains an endInclusive flag; indent/dedent pass it when the real selection continues past the block (to > contentEnd), so a trailing empty line at the clamped end is now included only in that case. A selection genuinely ending at that line start keeps the exclusive-boundary rule. Regression tests added for both commands (code_block("a\n") + code_block("b") cross-block, plus the exact-end control case). Laptop: bun vitest indent.test.ts 31/31 pass, tsc --noEmit clean.

@dezren39

Copy link
Copy Markdown
Member Author

Fmt/lint fix pushed: web-fmt/biome named indent.ts (biome format applied) and web-lint flagged indent.test.ts:79 (forEach callback returning push() result — now a block body). Verified on laptop: biome lint clean on both files, vitest indent.test.ts 31/31 pass. Re-dispatching id-check for the new head.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 8bfaaf5da4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@dezren39
dezren39 merged commit 9813b78 into main Oct 31, 2026
2 of 3 checks passed
@dezren39
dezren39 deleted the queue/1682-1399-multiblock-indent branch October 31, 2026 03:08
@dezren39
dezren39 restored the queue/1682-1399-multiblock-indent branch November 1, 2026 07:51
@dezren39
dezren39 deleted the queue/1682-1399-multiblock-indent branch November 1, 2026 16:46
@dezren39

dezren39 commented Nov 8, 2026

Copy link
Copy Markdown
Member Author

🤖 Agent note · salvage check (duplicate PR disposition)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

id(web): Tab/Shift-Tab with a selection spanning multiple blocks corrupts a paragraph and skips later code blocks

1 participant